import { request } from '@/utils/request';

import { PageParams } from './model/pageParams';

/**
 * 售后状态：0-待处理 1-处理中 2-已完成 3-已拒绝
 */
export interface AfterSales {
  id: number;
  orderId: number;
  userId: number;
  type: number; // 类型：0-退款 1-退货退款 2-换货
  reason: string;
  description: string;
  images: string;
  status: number;
  handleNote: string;
  createTime: string;
  updateTime: string;
}

/**
 * 分页查询
 */
export const page = (params: PageParams) => {
  return request.post({
    url: '/after-sales/page',
    data: params,
  });
};

/**
 * 获取售后详情
 */
export const getAfterSales = (id: number) => {
  return request.get({
    url: `/after-sales/info/${id}`,
  });
};

/**
 * 处理售后申请
 */
export const handleAfterSales = (id: number, status: number, handleNote?: string) => {
  return request.post({
    url: '/after-sales/handle',
    params: {
      id,
      status,
      handleNote,
    },
  });
};

/**
 * 检查订单是否可以申请售后
 */
export const checkAfterSales = (orderId: number) => {
  return request.get({
    url: `/after-sales/check/${orderId}`,
  });
};
